package club.terroir.server.folder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.google.appengine.api.datastore.Key;

@Entity
public class Folder_SS implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key key;

	private String name;

	private Boolean isRoot = null;

	private String idOwner = null;

	@ManyToOne(fetch = FetchType.EAGER)
	private Folder_SS parent;

	@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
	private List<Folder_SS> listFolderChildreen = new ArrayList<Folder_SS>();
	
	@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
	private List<Produit_SS> listProduitsChildreen = new ArrayList<Produit_SS>();

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the key
	 */
	public Key getKey() {
		return key;
	}

	/**
	 * @param key
	 *            the key to set
	 */
	public void setKey(Key key) {
		this.key = key;
	}

	/**
	 * @return the listFolderChildreen
	 */
	public List<Folder_SS> getListFolderChildreen() {
		return listFolderChildreen;
	}

	/**
	 * @param listFolderChildreen
	 *            the listFolderChildreen to set
	 */
	public void setListFolderChildreen(List<Folder_SS> listFolderChildreen) {
		this.listFolderChildreen = listFolderChildreen;
	}

	/**
	 * @return the listProduitsChildreen
	 */
	public List<Produit_SS> getListProduitsChildreen() {
		return listProduitsChildreen;
	}

	/**
	 * @param listProduitsChildreen
	 *            the listProduitsChildreen to set
	 */
	public void setListProduitsChildreen(List<Produit_SS> listProduitsChildreen) {
		this.listProduitsChildreen = listProduitsChildreen;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return super.toString() + " FOLDER| name : " + name + " | key :" + key+" | children.size "+listFolderChildreen.size();
	}

	/**
	 * @return the isRoot
	 */
	public boolean isRoot() {
		return isRoot;
	}

	/**
	 * @param isRoot
	 *            the isRoot to set
	 */
	public void setRoot(boolean isRoot) {
		this.isRoot = isRoot;
	}

	/**
	 * @return the idOwner
	 */
	public String getIdOwner() {
		return idOwner;
	}

	/**
	 * @param idOwner
	 *            the idOwner to set
	 */
	public void setIdOwner(String idOwner) {
		this.idOwner = idOwner;
	}

	/**
	 * @return the isRoot
	 */
	public Boolean getIsRoot() {
		return isRoot;
	}

	/**
	 * @return the parent
	 */
	public Folder_SS getParent() {
		return parent;
	}

	/**
	 * @param isRoot the isRoot to set
	 */
	public void setIsRoot(Boolean isRoot) {
		this.isRoot = isRoot;
	}

	/**
	 * @param parent the parent to set
	 */
	public void setParent(Folder_SS parent) {
		this.parent = parent;
	}

}
